package com.topisv.tms.repository.qimen;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.qimen.QmResendInfo;

/**
 * create by gaohuan 2015 07 06
 * */
public interface QmResendInfoDao extends PagingAndSortingRepository<QmResendInfo, Long>, JpaSpecificationExecutor<QmResendInfo> {
	/*
	 * 查询未重发成功并重试次数超出5次的数据
	 * */
	@Query("select t from QmResendInfo t where (sendResult = 'new' or sendResult = 'undo') and resendCount < 5 and lockTask = 'unlock' ")
	public List<QmResendInfo> findBySendResultAndResendCount();
	
	/*
	 * 删除已重发成功的15天以前的数据
	 * */
	@Modifying
	@Query("delete from QmResendInfo where datediff(curdate(),resendTime) > 15  and sendResult = 'do' ")
	public void deleteOverTimeData();

}
